fix: INTL0101 code fix NotImplementedException for non-class declaration types#411
fix: INTL0101 code fix NotImplementedException for non-class declaration types#411BenjaminMichaelis merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the INTL0101 (“Attributes on separate lines”) code fix to avoid NotImplementedException and expands test coverage so the fix works for more declaration kinds beyond classes.
Changes:
- Generalize the code fix to operate on
MemberDeclarationSyntaxrather than only class/method/property/field nodes. - Add code-fix tests covering structs, records, interfaces, enums, constructors, enum members, and indexers.
- Reformat/normalize
Directory.Packages.props(appears to be non-semantic churn).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs | Adds new code-fix tests for additional declaration types (struct/record/interface/enum/etc.). |
| IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/AttributesOnSeparateLines.cs | Broadens the code fix to handle more declaration syntax kinds by switching to MemberDeclarationSyntax. |
| Directory.Packages.props | Entire file rewritten with no apparent semantic version changes (likely line-ending/format normalization). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/AttributesOnSeparateLines.cs
Outdated
Show resolved
Hide resolved
84d613f to
99029ec
Compare
4078a22 to
3209f9d
Compare
…on types The AttributesOnSeparateLines code fix only handled ClassDeclarationSyntax, MethodDeclarationSyntax, PropertyDeclarationSyntax, and FieldDeclarationSyntax. Any other declaration type flagged by the analyzer (structs, records, interfaces, enums, constructors, enum members, indexers, etc.) would throw NotImplementedException when a user tried to apply the code fix. Replace the two switch expressions with a MemberDeclarationSyntax base class pattern match in RegisterCodeFixesAsync, so unsupported node types silently skip registering the code fix rather than crash. PutOnSeparateLine is updated to accept MemberDeclarationSyntax directly, calling AttributeLists and WithAttributeLists() without any helper switch methods. Add code fix tests for: struct, record, interface, enum type, constructor, enum member, and indexer declarations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3209f9d to
a254af7
Compare
There was a problem hiding this comment.
Pull request overview
Updates the INTL0101 “Attributes on separate lines” code fix to avoid NotImplementedException when the diagnostic is reported on additional declaration kinds beyond the originally handled set, and expands unit test coverage accordingly.
Changes:
- Generalize the code fix to operate on
MemberDeclarationSyntaxand remove the previous type-switch helpers that threw for unhandled declaration kinds. - Add code-fix tests for structs, records, interfaces, enums, constructors, enum members, and indexers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/AttributesOnSeparateLines.cs | Broadens the code fix to work on any MemberDeclarationSyntax and removes the prior switch/NotImplementedException path. |
| IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs | Adds new test cases to validate the code fix for additional declaration/member types. |
Comments suppressed due to low confidence (1)
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/AttributesOnSeparateLines.cs:74
- The code fix rebuilds new AttributeListSyntax instances without preserving the original AttributeList's Target (e.g.,
[field: ...],[method: ...]) and also recreates AttributeSyntax nodes, which can drop trivia/comments. This can change semantics for targeted attributes and may delete user comments. PreserveAttributeListSyntax.Targetwhen splitting, and prefer reusing/copying the existingAttributeSyntaxnodes (including trivia) rather than recreating them fromName/ArgumentList.
foreach (AttributeSyntax attribute in parentDeclaration.AttributeLists.SelectMany(l => l.Attributes))
{
attributeLists = attributeLists.Add(
SyntaxFactory.AttributeList(
SyntaxFactory.SeparatedList(
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Describe your changes here.
Fixes #Issue_Number (if available)
Ensure that your pull request has followed all the steps below: